﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LinkyPOS.Class
{
    class masraflar2
    {
        linkDataContext ly = new linkDataContext();
        private int masrafID;
        private double tutar;
        private string tip;
        private string aciklama;
        private DateTime date;
        private double toplamtutar;


        public int Masrafid { get { return masrafID; } set { masrafID = value; } }
        public double Tutar { get { return tutar; } set { tutar = value; } }
        public double Toplamtutar { get { return toplamtutar; } set { toplamtutar = value; } }

        public string Tip { get { return tip; } set { tip = value; } }

        public string Aciklama { get { return aciklama; } set { aciklama = value; } }

        public DateTime Date { get { return date; } set { date = value; } }

        public masraflar2()
        { }

        public void masrafekle()
        {

            masraflar ms = new masraflar()
            {
                tutari = tutar,
                turu = tip,
                aciklama = aciklama,
                tarih = date
            };

            ly.masraflars.InsertOnSubmit(ms);
            ly.SubmitChanges();


        }

   
        public void masrafgetir(object obj)
        {
           
            ListView listview = (ListView)obj;
            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("select * from masraflar where tarih=getdate() order by tarih asc",sqlcon);
            sqlcon.Open();

            SqlDataReader sdr = sqlcmd.ExecuteReader();
            
            while (sdr.Read())
            {
                ListViewItem lst = new ListViewItem();
                lst.Text = sdr["masrafID"].ToString();
                lst.SubItems.Add(sdr["tutari"].ToString());
                lst.SubItems.Add(sdr["turu"].ToString());
                lst.SubItems.Add(sdr["aciklama"].ToString());

                listview.Items.Add(lst);

            }
            sqlcon.Close();
          
        
        
        }

        public void gunlukmasraf()
        {  try
        {
            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("select sum(tutari) as toplamtutar from masraflar where tarih=@date",sqlcon);
            sqlcmd.Parameters.AddWithValue("@date", dateandunit.sadecetarih());
            sqlcon.Open();
            SqlDataReader sdr = sqlcmd.ExecuteReader();
            while (sdr.Read())
            {
              toplamtutar=Convert.ToDouble(sdr["toplamtutar"]);

            }
            sqlcon.Close();
            }
            catch (Exception)
            {
                
               
            }
        }


        public void gunlukmasraf(DateTime tarih)
        {
            try
            {
                var gmasraf = (from m in ly.masraflars
                              select m.tutari).Sum();

                
            }
            catch (Exception)
            {


            }
        }
    }
}
